import aiohttp
import asyncio
import zipfile
from io import BytesIO
#url = "http://127.0.0.1:8000/log/P10.20-5C63F42D5A524ED3BC58A346E2E2DB03/20210524"


def unzip(data):
    with zipfile.ZipFile(data) as f:
        f.extractall("d:\\bb")

async def log():
    url = "http://127.0.0.1:8000/log/*/20210524"
    async with aiohttp.ClientSession() as client:
        async with client.get(url) as resp:
            if resp.status == 200:
                data = await resp.read()
                unzip(BytesIO(data))
                # with open("d:\\"+resp.content_disposition.filename, 'wb') as f:
                #     f.write(data)
                #     print("ok")
            else:
                error = await resp.json()
                print(error)

async def task():
    url = "http://127.0.0.1:8000/task/*/802327"
    async with aiohttp.ClientSession() as client:
        async with client.get(url) as resp:
            if resp.status == 200:
                data = await resp.read()
                with open("d:\\"+resp.content_disposition.filename, 'wb') as f:
                    f.write(data)
                    print("ok")
            else:
                error = await resp.json()
                print(error)
if __name__ == "__main__":
    asyncio.run(log())